const state = {
  h5EncryptKey: '',
  SM2_Pubkey: '',
  RSA_Pubkey: '',
  UUID_List: [],
  // 是否开启加密 目前环境要求必须加密
  encryptOn: true
}
const mutations = {
  SET_H5ENCRYPTKEY: (state, h5EncryptKey) => {
    state.h5EncryptKey = h5EncryptKey
  },
  SET_SM2_PUBKEY: (state, SM2_Pubkey) => {
    state.SM2_Pubkey = SM2_Pubkey
  },
  SET_RSA_PUBKEY: (state, RSA_Pubkey) => {
    state.RSA_Pubkey = RSA_Pubkey
  },
  ADD_ITEM: (state, item) => {
    // eg: { id: param.extension['uuid'], key: sm4Key, salt: salt }
    // eg: { id: param.extension['uuid'], key: AESKey, iv: iv, salt: salt }
    state.UUID_List.push(item)
  },
  DEL_ITEM: (state, id) => {
    state.UUID_List.map((v, i) => {
      if (v.id === id) {
        state.UUID_List.splice(i, 1)
      }
    })
  }
}
const actions = {
  add_item({ commit }, item) {
    commit('ADD_ITEM', item)
  },
  del_item({ commit }, id) {
    commit('DEL_ITEM', id)
  }
}
const getters = {
  getKey: (state) => (id) => {
    return state.UUID_List.find(item => item.id === id)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
